﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XStudio.WebFramework.Mvc.Filter;
using XStudio.Framework.Extensions;
using XStudio.Core.Ext.ConvertExtensions;
using Core.Manage.Product;
using XStudio.WebFramework.Support;
using Core.Manage.User;

namespace Admin.Areas.Product.Controllers
{
    [AuthorizeFilter]
    [Description("生资产品")]
    public class GoodsProductTypeController : Controller
    {
        #region 添加生资产品类型
        /// <summary>
        /// 添加生资产品类型
        /// </summary>
        /// <returns></returns>
        [Description("添加生资产品类型")]
        public ActionResult Create()
        {
            var entity = new GoodsProductTypeEntity();
            return View(entity);
        }

        /// <summary>
        /// 提交添加IMEI数据
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Create(int productTypeID, GoodsProductTypeEntity entity, FormCollection collection)
        {
            var result = GoodsProductTypeRule.Instance.Insert(productTypeID, entity.Name, UserAppI.CurrentUser.UID);

            return Json(result, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 获取生资产品类型表
        /// <summary>
        /// 获取生资产品类型表
        /// </summary>
        /// <returns></returns>
        [AuthorizeFilter(true)]
        [Description("获取生资产品类型表")]
        public ActionResult List()
        {
            return View();
        }

        /// <summary>
        /// 按条件查询列表信息
        /// </summary>
        /// <returns></returns>
        [AuthorizeFilter(true)]
        [HttpPost]
        public ActionResult ListData()
        {
            int pageNo = Request["page"].ToInt32();
            if (pageNo < 1)
                pageNo = 1;
            int pageSize = Request["rows"].ToInt32();
            if (pageSize < 10)
                pageSize = 30;
            var searchCondition = " 1=1 ";

            //搜索条件
            if (!string.IsNullOrWhiteSpace(Request["SearchWord"]))
            {
                var searchWord = Request["SearchWord"].LikeFilter();
                searchCondition += string.Format(" AND (IMEI LIKE '%{0}%')", searchWord);
            }

            var data = GoodsProductTypeVWRule.Instance.GetGridDataByPage(pageSize, pageNo - 1, true, searchCondition);
            return Json(data, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 删除生资产品类型
        [Description("删除生资产品类型")]
        public ActionResult Delete(int id)
        {
            return Json(GoodsProductTypeRule.Instance.Delete(id), JsonRequestBehavior.AllowGet);
        }
        #endregion

   
    }
}